package utils;
import java.text.SimpleDateFormat;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;
import net.sf.json.util.CycleDetectionStrategy;

public class JsonConfigUtil implements JsonValueProcessor {

	private static JsonConfigUtil jsonValueProcessor = new JsonConfigUtil();
	private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
	
	private JsonConfigUtil() {
		super();
	}

	public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {
		// TODO Auto-generated method stub
		return value==null?"":sd.format(value);
	}
	
	public Object processArrayValue(Object value, JsonConfig jsonConfig) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public static JsonConfig getConfig() {
		JsonConfig config = new JsonConfig();
		config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
		config.registerJsonValueProcessor(java.util.Date.class,jsonValueProcessor);
		return config;
	}
}
